<?php
require_once($application_folder."/controllers/navigator.php");
class Column extends Navigator{

    function __construct(){
        parent::__construct();
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
        $this->load->model('articlem','art');
        $this->load->helper('date');
        //$this->output->cache(5);
    }

    function index(){
        //show_404();
        $this->preview();
    }

    function preview(){
        
        /************************************************************
        * GET COLUMN AND SUBCOLUMN
        *************************************************************/
        $data['columns'] = $this->db->get('column')->result_array();
        $data['subcolumns'] = $this->db->get('subcolumn')->result_array();

        $this->core_cms('column', $data, 'preview');                                  
    }

    function newform(){

        /************************************************************
        * GET COLUMN, SUBCOLUMN, TAGS
        *************************************************************/
        $data['columns'] = $this->db->get('column')->result_array();
        $data['subcolumns'] = $this->db->get('subcolumn')->result_array();
        if(isset($_GET['subcolumnid'])){
            $data['columnname'] = $this->db->get_where('subcolumn', array('id' => $_GET['subcolumnid']))->result_array();    
        }
        

        $this->core_cms('column', $data, 'new_edit_form');                                  
    }
    
    function edit_insert(){
        
        switch ($_POST['appmode']){
            
            case 'insert':
            $this->db->insert('subcolumn', array('name' => $_POST['name'], 'column_id' => $_POST['column_id']));
            echo json_encode(array('action'=> true)); 
            break;
            
            case 'edit':
            
            $this->db->where('id', $_POST['subcolumn_id']);
            $this->db->update('subcolumn', array('name' => $_POST['name'], 'column_id' => $_POST['column_id']));
            
            echo json_encode(array('action'=> true));
            
            break;
            
        }
        
    }
    
    function deleteone(){
        
        $this->db->where('id',$_POST['id']);
        $this->db->delete('subcolumn');
        echo json_encode(array('action'=> true));
    }

}